<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        var msg = "消息";

        // 1、用户访问该页面后，H1显示msg变量值
        // 2、用户访问该页面后，input的默认值显示msg
        window.onload = function(){
            var h1Dom = document.getElementById("h1");
            var inputDom = document.getElementById("input");
            h1Dom.innerHTML = msg;
            inputDom.value = msg;
            // 3、当用户在页面中操作input框，将用户对于input框的值 存储到 msg 变量上
            inputDom.addEventListener("input",function(){
                // console.log(this.value);
                msg = this.value;
                console.log("msg:",msg);
                // 4、当内存变量msg 发生变化时，将页面中H1标签值进行同步更新
                h1Dom.innerHTML = msg;
            });
        }
    </script>
</head>
<body>
    <h1 id="h1"></h1>
    <input type="text" id="input">
</body>
</html>